package com.dyp.mybatisdemo;

import com.dyp.mybatisdemo.repository.PersonMapper;
import com.dyp.mybatisdemo.service.PersonService;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan({"com.dyp.mybatisdemo.repository"})
public class MybatisDemoApplication implements CommandLineRunner {
	private Logger logger = LoggerFactory.getLogger(MybatisDemoApplication.class);

	@Autowired
	PersonService personService;

	public static void main(String[] args) {
		SpringApplication.run(MybatisDemoApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		logger.debug("=======================with first cache==============================");
		personService.getPersonByFirstCache("1");
		logger.debug("=====with first cache, but cross transaction, cache invalidation=====");
		personService.getPersonByFirstCache("1");
		logger.debug("========================without cache================================");
		personService.getPersonWithoutCache("1");
		logger.debug("========================with second cache============================");
		personService.getPersonWithSecondCache("1");
		logger.debug("===with second cache,but cross transaction, cache still validation===");
		personService.getPersonWithSecondCache("1");
	}
}
